package com.haojiang.mh.remote.ui.frag

import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.haojiang.mh.R
import com.haojiang.mh.remote.adapter.GroupTypeDialogFragAdapter
import com.haojiang.mh.remote.base.BaseFrag
import com.haojiang.mh.remote.utils.BleUtil.Companion.groupData
import kotlinx.android.synthetic.main.frag_dialog_group_type.rvGroupType
import kotlinx.android.synthetic.main.frag_first.*


class FragFirst : BaseFrag() {

    private val groupTypeDialogFragAdapter = GroupTypeDialogFragAdapter()

    override fun onLayoutId(): Int {
        return R.layout.frag_first
    }

    override fun initView() {
//        return View.inflate(context, R.layout.frag_first, null)
    }


    override fun initListener() {
        groupTypeDialogFragAdapter.clearData()
        rvGroupType.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
        rvGroupType.layoutManager = LinearLayoutManager(context)
        rvGroupType.adapter = groupTypeDialogFragAdapter

        etGroupName.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }

            override fun afterTextChanged(s: Editable?) {
                groupData.groupKey.name = s.toString()
            }
        })
        groupData.groupKey.name = etGroupName.text.toString()
    }

}